package com.example.restaurantclient.Fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.restaurantclient.Activity.LoginActivity;
import com.example.restaurantclient.Activity.Shop.ShopActivity;
import com.example.restaurantclient.AliPay.PayDemoActivity;
import com.example.restaurantclient.Entities.Variable;
import com.example.restaurantclient.R;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class PersonnalFragment extends Fragment {
    private View view;
    private LinearLayout reCharge;
    private Button btn_shop;
    private TextView balance;
    private TextView jiFen;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if(view==null) {
            view = inflater.inflate(R.layout.fragment_personnal, container, false);

        }
        ImageView memberIv=view.findViewById(R.id.iv_head);

        jiFen=view.findViewById(R.id.integration);
        reCharge=view.findViewById(R.id.linear_pay);
        btn_shop=view.findViewById(R.id.shop);
        balance=view.findViewById(R.id.balance);
        reCharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), PayDemoActivity.class));
            }
        });
        memberIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getContext(), LoginActivity.class);
                startActivity(intent);
            }
        });
        btn_shop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), ShopActivity.class);
                startActivity(intent);
            }
        });

        return  view;
    }

//    @Override
//    public void startActivityForResult(Intent intent, int requestCode) {
//        super.startActivityForResult(intent, requestCode);
//    }


    @Override
    public void onStart() {
        super.onStart();
        balance.setText(Variable.sumPrice+"");
        jiFen.setText(Variable.jiFen+"");
    }
    //处理事件的方法
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void updateUI(String msg){
//        //threadMode = ThreadMode.MAIN在主线程执行
//        if (msg.equals("update")) {
//            //刷新Adapter(修改UI)
//            balance.setText(Variable.sumPrice+"");
//        }
//    }
}
